1 00:00:00,310 --> 00:00:02,430 So now I think it's time to make our own weapon. 2 00:00:02,430 --> 00:00:04,290 We're going to make this handgun here. 3 00:00:04,290 --> 00:00:06,930 It shoots, it makes noise, it does damage. 4 00:00:06,930 --> 00:00:10,680 There's no bells and whistles, no animations yet, no reload yet. 5 00:00:10,680 --> 00:00:12,060 But we're going to get to that. 6 00:00:13,360 --> 00:00:14,270 Pretty cool. 7 00:00:14,290 --> 00:00:16,030 Let's go ahead and get started. 8 00:00:16,780 --> 00:00:22,180 Let's go over to our tool box and see if we can get a mesh part that looks good enough for a gun that 9 00:00:22,180 --> 00:00:22,750 we can use. 10 00:00:22,750 --> 00:00:25,210 That way we don't have to weld a bunch of pieces together. 11 00:00:25,210 --> 00:00:27,760 We don't want to use somebody else's model. 12 00:00:27,760 --> 00:00:29,920 We want to do all the coding ourselves. 13 00:00:29,920 --> 00:00:35,770 But the artwork is a different story because if you're like me, I can code really well, but I'm terrible 14 00:00:35,770 --> 00:00:39,460 at art, so I'm going to look for a pistol. 15 00:00:39,850 --> 00:00:43,210 Under Mashes meshes are a single part. 16 00:00:43,210 --> 00:00:48,940 It's been something's been imported from like Blender or somebody created something really nice and 17 00:00:48,940 --> 00:00:52,660 now it's just a single part with a mesh over top of it. 18 00:00:53,110 --> 00:00:55,450 I'm going to drag that in that says Texture. 19 00:00:55,480 --> 00:00:56,860 That looks great. 20 00:00:56,890 --> 00:00:58,840 I think I'm going to work with this. 21 00:00:58,840 --> 00:01:00,760 The gun is obviously too big. 22 00:01:00,760 --> 00:01:02,230 Let's go ahead and resize it. 23 00:01:02,230 --> 00:01:04,060 I'm going to close my tool box. 24 00:01:04,270 --> 00:01:04,930 There we go. 25 00:01:04,930 --> 00:01:06,010 We have more space. 26 00:01:06,010 --> 00:01:08,350 Select the gun hit scale. 27 00:01:08,350 --> 00:01:10,300 If it's not selected, you get those little dots. 28 00:01:10,300 --> 00:01:10,810 Right. 29 00:01:10,810 --> 00:01:16,480 And now we need to keep an eye on our size so when we resize it so mesh part is selected, that's the 30 00:01:16,480 --> 00:01:16,990 gun. 31 00:01:16,990 --> 00:01:21,460 Let's go down to size seven, 7.6. 32 00:01:21,460 --> 00:01:23,620 That's the X. 33 00:01:23,620 --> 00:01:25,540 So that's the thickness of the gun. 34 00:01:25,540 --> 00:01:30,280 That should be about 0.25 studs, not seven and one half. 35 00:01:30,430 --> 00:01:38,830 Hold the shift down, so everything shrinks maintaining the aspect ratio and then just drag this down 36 00:01:39,310 --> 00:01:42,970 until that's about .25. 37 00:01:45,880 --> 00:01:47,360 Uh, there you go. 38 00:01:47,390 --> 00:01:47,980 Oh, look at that. 39 00:01:47,980 --> 00:01:48,790 That's pretty good. 40 00:01:49,300 --> 00:01:52,960 All right, now let's go to our workspace. 41 00:01:53,170 --> 00:01:54,490 Hit the plus. 42 00:01:55,180 --> 00:01:56,360 Add a tool. 43 00:01:56,380 --> 00:02:02,190 So tools are special roadblocks, objects that the characters and players can use. 44 00:02:02,200 --> 00:02:03,990 They can carry it in your hand. 45 00:02:04,000 --> 00:02:10,750 Let's call that tool simple pistol, because a pistol is something we want to carry in our hand. 46 00:02:10,960 --> 00:02:17,230 Let's grab the mesh part, which is the gun, drag it into the simple pistol. 47 00:02:17,440 --> 00:02:20,760 Now all tools have to have a handle to pick it up. 48 00:02:20,770 --> 00:02:25,600 I don't think I'm going to call my mesh part handled because then we have to work on the grip. 49 00:02:25,690 --> 00:02:32,640 Let's just call the mesh part, gun part, and then I'm going to add a separate handle. 50 00:02:32,650 --> 00:02:38,290 That way I can move it around and just eyeball it for how I want my grip. 51 00:02:38,440 --> 00:02:39,970 I'm going to hit P for part. 52 00:02:41,340 --> 00:02:42,270 There we go. 53 00:02:42,780 --> 00:02:44,210 Make sure collisions are off. 54 00:02:44,220 --> 00:02:46,470 We're going to put the part inside the gun. 55 00:02:47,380 --> 00:02:48,880 Let's get our gun part. 56 00:02:49,270 --> 00:02:50,440 Let me get the position. 57 00:02:50,440 --> 00:02:52,390 I'll do C frame position. 58 00:02:52,390 --> 00:02:54,650 Control C of the gun part. 59 00:02:54,670 --> 00:02:58,600 Go to my part, part and then control V. 60 00:02:59,350 --> 00:03:00,860 And now it's centered. 61 00:03:00,880 --> 00:03:03,130 Let's change the size of our part. 62 00:03:04,070 --> 00:03:08,210 My go to size, I'm going to make it kind of small. 63 00:03:09,020 --> 00:03:13,760 But before we do that, let's see where the front of that part is. 64 00:03:14,860 --> 00:03:16,540 I might add, the plus sign. 65 00:03:18,130 --> 00:03:19,300 Add a decal. 66 00:03:19,300 --> 00:03:22,390 So the front is actually pointing to the left. 67 00:03:22,390 --> 00:03:26,710 We need the handle to be pointing in the same direction as the gun. 68 00:03:26,710 --> 00:03:32,500 If we pick it up and we want it to be facing the right direction for our character, let's grab that 69 00:03:32,500 --> 00:03:33,490 part. 70 00:03:34,340 --> 00:03:35,880 And we can get rid of the cow. 71 00:03:35,900 --> 00:03:38,990 It's going to move around like that if you hover over it. 72 00:03:39,260 --> 00:03:43,880 We know that we need to change it so that it's facing the opposite direction. 73 00:03:44,390 --> 00:03:45,210 There we go. 74 00:03:45,230 --> 00:03:46,730 Now it's facing front. 75 00:03:46,760 --> 00:03:49,430 Now I can change my size. 76 00:03:49,460 --> 00:03:51,660 If it's too small, it's hard to see the decal. 77 00:03:51,680 --> 00:03:53,450 That's why I wanted to do that first. 78 00:03:54,020 --> 00:03:55,550 It's pretty small now. 79 00:03:56,090 --> 00:03:58,370 Let's get our move. 80 00:03:58,400 --> 00:03:59,240 I'm going to put. 81 00:03:59,510 --> 00:04:00,610 This is going to be my handle. 82 00:04:00,620 --> 00:04:03,170 I'm going to put it right where my hand is supposed to be. 83 00:04:03,170 --> 00:04:04,250 On the gun. 84 00:04:04,990 --> 00:04:05,450 Yeah, that's. 85 00:04:05,450 --> 00:04:06,890 That's pretty good like that. 86 00:04:06,920 --> 00:04:09,200 Now, let's rename it to handle. 87 00:04:09,200 --> 00:04:11,640 It has to be spelled like that. 88 00:04:11,660 --> 00:04:13,370 If it's not, it won't work. 89 00:04:13,580 --> 00:04:16,370 Let's go to our simple pistol. 90 00:04:16,400 --> 00:04:17,600 Hit the plus. 91 00:04:17,630 --> 00:04:23,150 When I add this weld constraint to stick the handle on the gun part, so click. 92 00:04:23,150 --> 00:04:28,310 The weld constraint hit part zero gun part. 93 00:04:28,520 --> 00:04:31,490 Part one handle part. 94 00:04:31,490 --> 00:04:33,110 And you could do it in any order. 95 00:04:33,560 --> 00:04:35,280 All right, let's try and pick it up. 96 00:04:35,300 --> 00:04:38,840 Let's do a play from here so you don't have to run around looking for that little gun. 97 00:04:41,900 --> 00:04:44,330 And look at that. 98 00:04:45,970 --> 00:04:47,230 Oh, that's pretty good, too. 99 00:04:47,470 --> 00:04:48,250 I like that. 100 00:04:48,250 --> 00:04:49,750 This is the one I had. 101 00:04:50,860 --> 00:04:52,750 And this is the one I just did now. 102 00:04:53,720 --> 00:04:54,740 All right. 103 00:04:55,330 --> 00:04:57,060 Now I need a gun sound. 104 00:04:57,070 --> 00:05:00,040 So let's go ahead and hit Stop. 105 00:05:00,040 --> 00:05:02,810 And we got to find a bang for the gun. 106 00:05:02,830 --> 00:05:07,600 Let's go to our toolbox and we'll do audio. 107 00:05:08,920 --> 00:05:12,640 I'll say bang or let's just look for gun. 108 00:05:12,640 --> 00:05:13,120 Gun. 109 00:05:13,120 --> 00:05:14,650 GUNSHOT one was there. 110 00:05:15,820 --> 00:05:17,170 Not bad. 111 00:05:17,530 --> 00:05:18,580 Let's go ahead and click. 112 00:05:18,580 --> 00:05:20,170 I'm going to put it on my gun part. 113 00:05:20,170 --> 00:05:22,840 So we have we have distance roll off. 114 00:05:22,840 --> 00:05:29,740 If you put sound in the workspace, if it's attached to an attachment or a bass part, you're going 115 00:05:29,740 --> 00:05:31,870 to get a sound roll off with distance. 116 00:05:31,870 --> 00:05:33,880 Let's do that insert. 117 00:05:33,880 --> 00:05:36,640 So the gunshot is under the gun part. 118 00:05:36,850 --> 00:05:39,490 I'm going to rename it to Bang. 119 00:05:42,130 --> 00:05:42,490 Good. 120 00:05:42,490 --> 00:05:44,290 And I can close this now. 121 00:05:44,290 --> 00:05:45,350 I think we're set. 122 00:05:45,370 --> 00:05:47,320 It's time to start scripting. 123 00:05:47,320 --> 00:05:53,530 Let's go to our simple pistol, Hit the plus and add a local script. 124 00:05:55,000 --> 00:06:00,370 The local script is going to be used to handle our mouse clicks and stuff when we're aiming. 125 00:06:00,370 --> 00:06:03,010 So let's call that shoot. 126 00:06:03,040 --> 00:06:11,680 Now you can't damage somebody or something on the server side with a local script, you need a server 127 00:06:11,680 --> 00:06:12,010 script. 128 00:06:12,010 --> 00:06:17,590 So go to simple pistol, hit the plus, hit an -- and then just get script. 129 00:06:17,590 --> 00:06:19,120 That's a server script. 130 00:06:19,240 --> 00:06:22,380 I'm going to call this damage, right? 131 00:06:22,390 --> 00:06:26,080 We're going to probably do more than damage, but it's a good it's a good place to start. 132 00:06:26,080 --> 00:06:30,730 You know, the damage is going to be a server script and now the shoot has to be able to talk to the 133 00:06:30,730 --> 00:06:31,510 damage. 134 00:06:31,510 --> 00:06:37,570 So what we're going to do is hit this plus hit an R and add a remote event. 135 00:06:37,570 --> 00:06:38,350 Right. 136 00:06:39,160 --> 00:06:40,540 Let's add that remote event. 137 00:06:40,540 --> 00:06:44,470 I'll call it Shoot Ray. 138 00:06:44,920 --> 00:06:45,170 Right. 139 00:06:45,400 --> 00:06:50,050 For shoot remote event, double click on your shoot local script. 140 00:06:50,050 --> 00:06:51,400 Make sure that's selected. 141 00:06:51,400 --> 00:06:52,030 There it is. 142 00:06:52,030 --> 00:06:52,140 Yeah. 143 00:06:52,150 --> 00:06:53,290 Little computer there. 144 00:06:53,400 --> 00:06:55,090 There we don't want the damage. 145 00:06:55,090 --> 00:06:56,320 We want to do the local script. 146 00:06:56,320 --> 00:06:56,890 First. 147 00:06:57,100 --> 00:07:01,270 I'm going to make a variable called Gun Script Dot Parent. 148 00:07:01,270 --> 00:07:04,540 So that's pointing to the tool, the simple pistol. 149 00:07:04,540 --> 00:07:08,320 Now I want to get a variable for my remote event. 150 00:07:08,620 --> 00:07:15,190 Shoot, Ray, It's on the gun, but we're going to have to do a wait for child, because if it's in 151 00:07:15,190 --> 00:07:17,320 our backpack, we could run into trouble. 152 00:07:18,040 --> 00:07:19,300 Shoot, Ray. 153 00:07:19,300 --> 00:07:20,740 We'll just wait for it. 154 00:07:21,100 --> 00:07:21,430 All right? 155 00:07:21,430 --> 00:07:23,830 I need a variable for my player. 156 00:07:24,280 --> 00:07:26,260 I will initialize that to nil. 157 00:07:26,410 --> 00:07:29,020 I need a variable for my mouse. 158 00:07:29,200 --> 00:07:33,400 Also initialize that to nil and my connection. 159 00:07:33,580 --> 00:07:35,260 You're going to see what that's for. 160 00:07:35,260 --> 00:07:36,940 But it's nil right now. 161 00:07:37,420 --> 00:07:40,750 Now I need a couple of functions. 162 00:07:40,750 --> 00:07:44,110 I need a function for activated. 163 00:07:44,110 --> 00:07:49,330 When I go to click on something, I'm going to call that on activated. 164 00:07:49,900 --> 00:07:53,230 And this is where we're going to fire our remote event. 165 00:07:53,230 --> 00:07:54,580 So we'll have our shoot. 166 00:07:54,580 --> 00:07:58,600 Ray Colon Fire Server. 167 00:07:58,600 --> 00:08:03,820 So we did a fire client, but now we're doing a fire server we're going to send. 168 00:08:05,170 --> 00:08:08,080 Well, I forgot a plus sign or an equal sign right here. 169 00:08:08,620 --> 00:08:09,850 There we go. 170 00:08:09,880 --> 00:08:14,740 We are going to send the mouse target. 171 00:08:14,740 --> 00:08:18,520 If we have one mouse dot target, it could be nil. 172 00:08:20,410 --> 00:08:22,720 I know we haven't gotten the mouse yet, but that's all right. 173 00:08:22,720 --> 00:08:23,080 Don't worry. 174 00:08:23,080 --> 00:08:24,020 We're going to get to that. 175 00:08:24,040 --> 00:08:31,600 We're going to do local function on equipped when we put the gun on. 176 00:08:33,520 --> 00:08:35,140 That's where we're going to get our player. 177 00:08:35,140 --> 00:08:40,950 So player will then equal game dot players. 178 00:08:41,650 --> 00:08:42,790 Local player. 179 00:08:42,790 --> 00:08:48,900 We can do local player because this is a local script, but we're waiting before we put it on, right 180 00:08:48,910 --> 00:08:51,430 before we equip it, before we try to get it. 181 00:08:51,670 --> 00:08:59,110 Now we're going to get a mouse from the player, player Colon Get mouse. 182 00:08:59,500 --> 00:09:00,890 That's pretty convenient. 183 00:09:00,910 --> 00:09:03,010 Now we're going to do something a little bit different. 184 00:09:03,640 --> 00:09:10,390 This connection variable is actually going to point to my activated event. 185 00:09:10,810 --> 00:09:15,600 We're going to connect this to our on activate function. 186 00:09:15,610 --> 00:09:18,430 If you get two extra parentheses in there, get rid of that. 187 00:09:18,430 --> 00:09:24,160 We before have been doing our events just by putting it down here, making the connection, but now 188 00:09:24,160 --> 00:09:25,540 we're going to connect and disconnect. 189 00:09:25,540 --> 00:09:28,440 So we're going to use a variable a little bit different. 190 00:09:28,450 --> 00:09:37,540 I'm going to use almost the same structure for my unequipped, so I'm copying this to a control C control 191 00:09:37,540 --> 00:09:42,760 V and this is going to be on unequipped. 192 00:09:43,270 --> 00:09:48,250 And then what I'm going to do is I'm going to get my player, I'm going to make it nil, I'm going to 193 00:09:48,250 --> 00:09:54,850 get my mouse, I'll make that nil and my connection. 194 00:09:56,530 --> 00:09:59,020 Not Nell, but Colon. 195 00:09:59,440 --> 00:10:00,670 Disconnect. 196 00:10:00,670 --> 00:10:02,470 So this will clean up some resources. 197 00:10:02,470 --> 00:10:06,550 If you have a lot of people running around with guns, you might start chewing up some resources with 198 00:10:06,550 --> 00:10:07,120 that. 199 00:10:07,360 --> 00:10:17,110 Now, down here, we're going to get the gun and we have a quipped event that happens when you pick 200 00:10:17,110 --> 00:10:17,770 something up. 201 00:10:17,770 --> 00:10:24,120 That's a tool and we'll connect that to on equipped. 202 00:10:24,130 --> 00:10:33,220 We're going to get a tool dot unequipped event connect that to on unequipped. 203 00:10:33,490 --> 00:10:38,770 There it is and then our activated will be connected when we put it on. 204 00:10:39,100 --> 00:10:41,500 Now we need to work on our damage script. 205 00:10:41,500 --> 00:10:49,600 So if you recall, we have this on activated function that when we click on something, this will go 206 00:10:49,600 --> 00:10:55,200 off and then we're going to use a remote event to fire to the server, the mouse target. 207 00:10:55,210 --> 00:10:57,070 We're going to catch that in the damage script. 208 00:10:57,070 --> 00:11:01,060 So let's go to Damage or click on it here. 209 00:11:01,420 --> 00:11:07,450 If you didn't remember where you put it under the pistol, under the simple pistol, let's get a variable 210 00:11:07,450 --> 00:11:14,320 for our shoot re script Dot parent Wait for child shoot. 211 00:11:14,320 --> 00:11:20,380 Ray Let's get a variable for damage and we'll make it pretty weak so we can get like mods and stuff 212 00:11:20,380 --> 00:11:25,570 with our points and then we need to bang the sound script. 213 00:11:25,570 --> 00:11:26,830 Dot parent. 214 00:11:26,830 --> 00:11:28,780 It's on the gun part. 215 00:11:28,780 --> 00:11:32,020 Remember we put it on the gun part so we'd get some sound roll off. 216 00:11:32,020 --> 00:11:32,680 There it is. 217 00:11:32,680 --> 00:11:33,340 Bang. 218 00:11:33,370 --> 00:11:35,230 So we'll do a dot bang. 219 00:11:37,270 --> 00:11:42,430 I need a function local function on shoot. 220 00:11:42,430 --> 00:11:44,890 We are going to get the player. 221 00:11:44,890 --> 00:11:51,940 I know that we didn't pass the player, but since this is coming from a fire server on the client side, 222 00:11:51,940 --> 00:11:54,400 the player will get passed first no matter what. 223 00:11:54,430 --> 00:11:56,920 Then we're also going to get a target. 224 00:11:56,920 --> 00:11:58,360 That's the thing we clicked on. 225 00:11:58,360 --> 00:11:59,710 We pass that over. 226 00:12:00,280 --> 00:12:02,620 No matter now, the target might be nil. 227 00:12:02,620 --> 00:12:04,960 Whether is or not doesn't matter. 228 00:12:04,960 --> 00:12:07,810 We're going to do the bang play. 229 00:12:07,810 --> 00:12:10,090 We're going to make the sound because guns go off. 230 00:12:10,090 --> 00:12:11,380 Even if they don't hit anything. 231 00:12:11,740 --> 00:12:17,830 We'll do an if statement to check to see if the target is not nil. 232 00:12:17,830 --> 00:12:23,140 So if the target exists, that's the same as if not nil. 233 00:12:23,480 --> 00:12:23,950 Right. 234 00:12:23,950 --> 00:12:31,090 Just so you recall and I'm also going to check to see if the target parent exists, because sometimes 235 00:12:31,090 --> 00:12:35,890 when things are dying, the characters removed before a body part, sometimes you get an error. 236 00:12:35,890 --> 00:12:37,270 Just being careful. 237 00:12:37,510 --> 00:12:38,800 I did my bang. 238 00:12:38,800 --> 00:12:40,030 I'm check my target. 239 00:12:40,030 --> 00:12:42,700 Let's check for a humanoid to see if we can do some damage. 240 00:12:42,700 --> 00:12:51,730 So if the humanoid exists, we're going to do target dot parent We know that exists. 241 00:12:51,850 --> 00:12:57,310 Find first child That's a humanoid. 242 00:12:57,310 --> 00:13:03,580 If there is a humanoid underneath the parent of the target, we better check though because there might 243 00:13:03,580 --> 00:13:04,390 not be. 244 00:13:04,630 --> 00:13:11,240 Then we can do HUME Colon take damage and then we'll pass in our damage amount. 245 00:13:11,260 --> 00:13:15,970 Now, this isn't going to go off unless we catch that remote event, but we can do that easy enough. 246 00:13:15,970 --> 00:13:23,380 We're going to say shoot our dot on server event because we're we're on the server side with our damage 247 00:13:23,380 --> 00:13:30,940 script, connect on shoot, get rid of those two extra parentheses that Roblox likes to put in there. 248 00:13:30,940 --> 00:13:33,730 You only want the function name when you're connecting it. 249 00:13:34,000 --> 00:13:35,200 All right, let's try it. 250 00:13:35,380 --> 00:13:37,240 Let's go to our world. 251 00:13:37,240 --> 00:13:39,310 Oh, and the gun is floating around out there. 252 00:13:39,310 --> 00:13:45,850 Let's get the gun and let's move it down to our starter pack. 253 00:13:46,630 --> 00:13:51,490 Their starter pack that was going to be in our backpack when we start our game. 254 00:13:52,900 --> 00:13:54,150 I should not play from here. 255 00:13:54,160 --> 00:13:55,390 I'm going to have to run for something. 256 00:13:55,420 --> 00:13:55,930 That's okay. 257 00:13:55,960 --> 00:13:57,280 We can get a coin, right? 258 00:13:59,290 --> 00:14:00,370 Here's our pistol. 259 00:14:00,580 --> 00:14:01,390 There it is. 260 00:14:01,420 --> 00:14:02,380 Does it make noise? 261 00:14:03,270 --> 00:14:05,500 Does it give us an error? 262 00:14:05,530 --> 00:14:06,490 Nope. 263 00:14:06,550 --> 00:14:07,780 Oh, there's a coin. 264 00:14:07,810 --> 00:14:09,760 We'll go run for one of those zombies. 265 00:14:12,470 --> 00:14:13,490 There's a zombie. 266 00:14:20,730 --> 00:14:21,420 All right. 267 00:14:21,420 --> 00:14:24,000 Looking good and no errors. 268 00:14:24,000 --> 00:14:29,580 So we'll have to add a little kickback function to our to our pistol. 269 00:14:29,610 --> 00:14:33,890 We're going to keep track of kills with the pistol, at least player kills. 270 00:14:33,900 --> 00:14:39,770 We're going to add points for NPC kills, and then we've got to do reload animation. 271 00:14:39,780 --> 00:14:42,750 Got a lot of cool stuff that goes along with making a gun. 272 00:14:42,930 --> 00:14:45,120 I will see you in the next video.